Read Operation

To implement the Read operation, you need to implement a route that displays a list of all transactions. This route will handle GET requests, which are used to retrieve and display data in app.py.

The key steps to implement the Read operation are as follows:

  1. Create a function named get_transactions that uses render_template to return an HTML template named transactions.html. This function should pass the transactions to the template for display.

  2. Use the Flask @app.route decorator to map this function to the root (/) URL. This means that when a user visits the base URL of your application, Flask will execute the get_transactions function and return its result.

Click here for hint This function is a basic render_template function as implemented in the previous labs.
Click here for solution
  1. 1
  2. 2
  3. 3
  4. 4
  1. # Read operation: List all transactions
  2. @app.route("/")
  3. def get_transactions():
  4. return render_template("transactions.html", transactions=transactions)

Now, the code will look like this:
Correct code highlighted in red